﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using PMisuseAn.io;

namespace PMisuseAn
{
    /// <summary>
    /// Interaction logic for NewClusterWindow.xaml
    /// </summary>
    public partial class NewClusterWindow : Window
    {
        ContextInterface ci_;
        public NewClusterWindow(ContextInterface ci)
        {
            InitializeComponent();
            ci_ = ci;
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            string clusterName = project_name.Text;
            clusterName = clusterName.Trim();
            if (clusterName.Count() == 0)
            {
                MessageBoxResult result = MessageBox.Show("Empty name box!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            List<string> project_clusters = MisUseAnObjectsDB.loadAllClusters();
            foreach (string c in project_clusters)
            {
                if (c.Equals(clusterName))
                {
                    MessageBoxResult result = MessageBox.Show("Project name already exist", "Conflict", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }
            }
            MisUseAnObjectsDB.addClusterDB(clusterName);
            MainWindow.clusterName = clusterName;
            ci_.loadContextInterface();
            generateDoNothingPolicy();
            this.Close();
        }
        private void generateDoNothingPolicy()
        {
            string formula_statement = "DO[NILL]";
            string transmissionPrinciple = "Null";
            MisUseAnObjectsDB.addPolicyStatement(formula_statement,transmissionPrinciple, MainWindow.clusterName);
        }
    }
}
